package com.topboya.linker.diyview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;


import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.MonthView;

import java.util.HashMap;

public class SimpleMonthView extends MonthView {

    private static final String TAG = "SimpleMonthView-";
    private int mRadius;
    private static HashMap<Integer, String> hashMapWeek;

    static {

        hashMapWeek = new HashMap<>();
        hashMapWeek.put(0, "星期日");
        hashMapWeek.put(1, "星期一");
        hashMapWeek.put(2, "星期二");
        hashMapWeek.put(3, "星期三");
        hashMapWeek.put(4, "星期四");
        hashMapWeek.put(5, "星期五");
        hashMapWeek.put(6, "星期六");

    }

    public SimpleMonthView(Context context) {
        super(context);
//         这里主要是设置画笔遮罩滤镜
        //兼容硬件加速无效的代码
//        setLayerType(View.LAYER_TYPE_SOFTWARE, mSelectedPaint);
        //4.0以上硬件加速会导致无效
//        mSelectedPaint.setMaskFilter(new BlurMaskFilter(25, BlurMaskFilter.Blur.SOLID));
    }

    @Override
    protected void onPreviewHook() {
        mRadius = Math.min(mItemWidth, mItemHeight) / 5 * 2;
        mSchemePaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onLoopStart(int x, int y) {

    }

    @Override
    protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {

        int cx = x + mItemWidth / 2;
        int cy = y + mItemHeight / 2;
        canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);

        return false;

    }

    @Override
    protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {

        int cx = x + mItemWidth / 2;
        int cy = y + mItemHeight / 2;
        canvas.drawCircle(cx, cy, mRadius, mSchemePaint);

    }

    @Override
    protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
        float baselineY = mTextBaseLine + y;
        int cx = x + mItemWidth / 2;
        int top = y - mItemHeight / 6;
        if (isSelected) {
            canvas.drawText(String.valueOf(calendar.getDay()), cx, mTextBaseLine + top,
                    mSelectTextPaint);
            canvas.drawText(hashMapWeek.get(calendar.getWeek()), cx, mTextBaseLine + y + mItemHeight / 10, mCurMonthLunarTextPaint);
            Log.v(TAG, calendar.getWeek() + "");
        } else if (hasScheme) {
            canvas.drawText(String.valueOf(calendar.getDay()),
                    cx,
                    baselineY,
                    calendar.isCurrentDay() ? mCurDayTextPaint :
                            calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);

        } else {
            canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
                    calendar.isCurrentDay() ? mCurDayTextPaint :
                            calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
        }
    }
//    private String getWeek(){
//
//
//    }
}
